import database
import matplotlib.pyplot as plt


# list the 5 most popular books for all people
def book_recommend():
    book_id_list = database.book_recommend()
    book_id = []
    book_info = []
    for item in book_id_list:
        book_id.append(item[0])
    for i in range(0, 5):
        book_info += database.book_search(id=book_id[i])
    return book_info


# use matplotlib to make a bar chart
def bar_chart():
    info = database.pd_data()
    book_id = []
    counts = []
    for item in info.keys():
        book_id.append(item)
    for item in info:
        counts.append(item)
    plt.bar(range(len(counts)), counts, color="red", tick_label=book_id)
    plt.title("books popularity")
    plt.xlabel("book_id")
    plt.ylabel("counts")
    plt.show()


if __name__ == "__main__":
    # recommend book list
    # book_recommend()
    # show the bar chart in program
    bar_chart()
